home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / Mem / c / Compact < prev    next >
Text File  |  1995-06-18  |  2KB  |  41 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Mem.Compact.c
  12.     Author:  Copyright © 1993, 1994, 1995 Jason Williams and Jason Howat
  13.     Version: 2.00 (18 Jun 1995)
  14.     Purpose: Dynamic memory manager - heap compaction
  15. */
  16.  
  17. #include "MemDefs.h"
  18.  
  19. extern void Mem_Compact(void)
  20. /*  Compacts the heap, moving all freespace to the end of the heap, and then
  21.  *  releases as much of this freespace as possible back into the WIMP freepool.
  22.  */
  23. {
  24.   if (mem__free < mem__pagesize) return;   /* Don't compact if not necessary */
  25.  
  26.   /* Gather all used chunks at beginning of heap */
  27.   Mem__ShuffleDown((mem_header *)mem__heap,
  28.                    (mem_header *)(mem__heap + mem__heapsize));
  29.  
  30.   /* Adjust the WimpSlot to the minimum that we require, adjusting the last
  31.    * chunk as appropriate
  32.    */
  33.   Mem__ReduceSlot();
  34.  
  35.   /* Update the count of free bytes in the heap */ 
  36.   if(ISFREE(mem__lastchunk))
  37.     mem__free = mem__lastchunk->realsize;
  38.   else
  39.     mem__free = mem__lastchunk->realsize - CHUNKSIZE(mem__lastchunk->datasize);
  40. }
  41.